package Exercises;

import java.util.LinkedList;
import java.util.Random;

public class MyThread extends Thread{
    private  int count = 0;

    LinkedList<String> list ;
    public MyThread(LinkedList<String> linkedList , String name){
        super(name);
        this.list = linkedList;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        Random r = new Random();
        while (true){
            synchronized (list){
                if (list.size() < 10){
                    break;
                }
                String s = list.remove(r.nextInt(list.size()));
                count++;
                System.out.println(name + " 成功送出了==> " + s);
            }
        }
    }

    public int getCount(){
        return count;
    }
}
